/**
  ******************************************************************************
  * @file    WWTG.c 
  * @author  Dajin Li
  * @version V0.0.1
  * @date    08-08-2015 
  * @brief   This file contains  WWTG function
  *			  	 
  *          
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; KION(SZ) R&D Center
  *
  * Licensed under KION, (the "License");
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "wwtg.h"

/**
* @brief	initial the wwatchdog timer.
* @param	none
* @note     none
* @retval   none
*/
void Wwatchdog_Init()
{
	/* Enable WWDG clock */
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

	WWDG_DeInit();
	
	Wwatchdog_Interrupt_Config();
	/* WWDG clock counter = (PCLK1/4096)/8 = 1098 Hz) 1ms */
	WWDG_SetPrescaler(WWDG_Prescaler_8);
	/* Set Window value to 65 */
	WWDG_SetWindowValue(0x41);
	WWDG_ClearFlag();	// Clear EWI flag   
	/* Enable WWDG and set counter value to 0x7F */
	WWDG_Enable(0x7F);  //1*64=64ms
	WWDG_EnableIT();   	//Enable EW interrupt   
}

/**
* @brief	Initial the window watchdog Interrupt
* @param	none
* @note     none
* @retval   none
*/

void Wwatchdog_Interrupt_Config()
{
	NVIC_InitTypeDef NVIC_InitStructure;

	/* Enable the RTC Interrupt */
	NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);
}


